<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 1.引入链接 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        html,body {
            width: 100%;
            height: 100%;
        }
    </style>

</head>
<body>
    <!-- 创建div模板 -->
    <div id="app">
        <h1>拾忆记事本</h1>
        <p>记录生活点点滴滴，写下生活每一个美好</p>

        <!-- <table class="table table-striped">
            
        </table> -->
        <ul style="width: 100%;height:800px;">
        <el-input type="text" v-model="value" @change="add()"></el-input>
            <li v-for="(item,index) in list" :key="index" style="display: flex;list-style:none;width: 100%;height: 60px;justify-content: space-between;">
                <span>{{index}}</span>
                <p style="margin: 0 200px;">{{item.title}}</p>
                <el-button @click="del(index)">删除</el-button>
            </li>
            <span>总数{{list.length}}</span>
        </ul>
        <el-empty v-show="list.length==0"></el-empty>
    </div>
</body>

</html>
<script>
    // 实例化vue
    new Vue({
        el: '#app',
        data: {
            value: '',
            list: JSON.parse(localStorage.getItem('list')) || []
        },
        methods: {
            add() {
                console.log(11111111111111111111)
                if (this.value == '') {
                    return alert('内容不能为空')
                }
                let obj = { title: this.value, flag: false }
                this.list.push(obj)
                this.setCity()
                this.value = ''
            },
            setCity() {
                localStorage.setItem('list', JSON.stringify(this.list))
            },
            del(index) {
                this.list.splice(index, 1)
                this.setCity()
            }
        },
        computed: {

        }
    })
</script>